﻿// The Text element contains only Text
define([
    'Wjs/ui/elements/Element',
    'Wjs/ui/elements/mixins/Loadable'
],
function () {
    'use strict';

    return Wjs.defineOnce({

        type: 'Text',

        internal: {

            base: Wjs.getType('Element'),

            mixins: [
                Wjs.getType('Loadable')
            ]
        },

        createDomElement: function () {

            this.domEl = document.createTextNode(this.text);

            this.text = null;  // Not needed after renedered
        },

        getText: function () {

            if (this.isRendered()) {

                return this.domEl.textContent;
            }
            else { // Not rendered

                return this.text;
            }
        },

        setText: function (text) {

            if (this.isRendered()) {

                this.domEl.textContent = text;
            }
            else { // Not rendered

                this.text = text;
            }

            return this;
        },

        getContent: function() {

            return this.getText();
        },

        // Called by the loader when the data is loaded
        loadHandler: function (data, contentType) {

            data = this.draw ? this.draw(data) : data;

            this.setText(data);
        },

        // Creates a copy of this element
        clone: function () {
            var cloned = Wjs.new(this.type);

            cloned.setText(this.getText());

            return cloned;
        }
    });

});